package com.kaifamiao.multiton;

/**
 * 多例: 某个类只能有有限个实例
 * 1、将构造方法私有化
 * 2、提供类变量来保存该类的有限个实例
 * 3、提供一个类方法用于获取指定的实例(可选,如果所有的类变量都是私有的则必须提供该方法)
 */
public class Season {
	
	// Eclipse 中可以通过 ctrl + shift + x 将被选中的单词统统改为 大写 
	// Eclipse 中可以通过 ctrl + shift + y 将被选中的单词统统改为 小写
	public static final Season SPRING = new Season( "春季" , "春暖花开" );
	public static final Season SUMMER = new Season( "夏季" , "烈日当空" );
	public static final Season AUTUMN = new Season( "秋季" , "秋高气爽" );
	public static final Season WINTER = new Season( "冬季" , "寒风刺骨" );
	
	private String name ;
	private String description ;
	
	public Season(String name, String description) {
		super();
		this.name = name;
		this.description = description;
	}

	public static Season getInstance( String name ) {
		// JDK 1.7 开始允许在 switch 中使用 String 类型
		switch( name ) {
			case "春季": return SPRING ;
			case "夏季": return SUMMER ;
			case "秋季": return AUTUMN ;
			case "冬季": return WINTER ;
			default: throw new RuntimeException( "季节名称错误" ) ;
		}
	}
	
	public String getName() {
		return name;
	}

	public String getDescription() {
		return description;
	}

	@Override
	public String toString() {
		return "Season [name=" + name + ", description=" + description + "]";
	}

}
